//
//  BIWebViewController.m
//  PurchasingMeeting
//
//  Created by zyhang on 1/20/14.
//  Copyright (c) 2014 YX. All rights reserved.
//

#import "BIWebViewController.h"
#import "DataManager.h"
#import "PMGlobal.h"
@interface BIWebViewController ()

@end

@implementation BIWebViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
#ifdef DHH_iOS
    UIWebView *web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height)];
    _web = web;
    [self.view addSubview:web];
    NSURLRequest *q = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:[[DataManager sharedManager]getUserObject].biURL]];
    [web loadRequest:q];
#else
    UIWebView *web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
    _web = web;
    [self.view addSubview:web];
    NSURLRequest *q = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:[[DataManager sharedManager]getUserObject].biURL]];
    [web loadRequest:q];
#endif
    [self setNavTitle:@"BI报表"];

    UIButton *b = [UIButton buttonWithType:UIButtonTypeCustom];
    UIImage *img = [[UIHelper getInstance] getBundleImage:@"anniu"];
    [b setBackgroundImage:img forState:UIControlStateNormal];
    [b setTitle:@"返回" forState:UIControlStateNormal];
    b.frame = CGRectMake(10, 10, 99, 37);
    [b addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *left = [[UIBarButtonItem alloc] initWithCustomView:b];
    self.navigationItem.leftBarButtonItem = left;
    
    
    b = [UIButton buttonWithType:UIButtonTypeCustom];
    img = [[PMGlobal getInstance]getretimage];
    [b setImage:img forState:UIControlStateNormal];
    b.frame = CGRectMake(10, 10, img.size.width, img.size.height);
    [b addTarget:self action:@selector(home) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *right = [[UIBarButtonItem alloc] initWithCustomView:b];
    self.navigationItem.rightBarButtonItem = right;

}

- (void)home{
    [self.navigationController dismissModalViewControllerAnimated:YES];
}

- (void)back{
    if ([_web canGoBack]) {
        [_web goBack];
    }else{
        [self.navigationController dismissModalViewControllerAnimated:YES];
    }
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
